package com.play.ballen.home.dialog

import android.app.Dialog
import android.content.Context
import android.graphics.drawable.ColorDrawable
import android.view.LayoutInflater
import android.view.View
import android.view.WindowManager
import android.widget.ImageView
import android.widget.TextView
import com.play.ballen.R
import com.yuven.baselib.utils.ResourceUtil

class PayDialogUtils(private val mContext: Context) {

    val dialog: Dialog = Dialog(mContext)
    private lateinit var contentView: View
    private lateinit var tvPrice: TextView
    private lateinit var tvSubTitle: TextView

    var valuesCallback: (() -> Unit)? = null

    fun show(price: String, week: String) {
        if (!this::contentView.isInitialized) {
            contentView =
                LayoutInflater.from(mContext).inflate(R.layout.dialog_pay, null)
            contentView.let {
                tvPrice = it.findViewById(R.id.tvPrice)
                tvSubTitle = it.findViewById(R.id.tvSubTitle)

                it.findViewById<ImageView>(R.id.imgClose).setOnClickListener { btn ->
                    dialog.dismiss()
                }
                it.findViewById<TextView>(R.id.btnOk).setOnClickListener { btn ->
                    dialog.dismiss()
                    valuesCallback?.invoke()
                }

                dialog.setContentView(it)
                dialog.setCanceledOnTouchOutside(false)
                dialog.window?.setLayout(
                    WindowManager.LayoutParams.MATCH_PARENT,
                    WindowManager.LayoutParams.WRAP_CONTENT
                )
                dialog.window?.setBackgroundDrawable(ColorDrawable())
            }
        }

        tvPrice.text = price
        tvSubTitle.text = ResourceUtil.getString(R.string.home_dialog_pay_sub_title, week)

        if (!dialog.isShowing) {
            dialog.show()
        }
    }

}